package com.yanyilu.qiubite.controller;

import com.yanyilu.qiubite.entity.Part;
import com.yanyilu.qiubite.service.StoryIndexService;
import com.yanyilu.qiubite.util.ParseJwtUtil;
import com.yanyilu.qiubite.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("storyIndex")
public class StoryIndexController {
    @Autowired
    StoryIndexService storyIndexService;

    //创建游戏进度
    @RequestMapping("/frontend/save")
    public R saveStoryIndex(@RequestParam("partId")Integer partId){
        Integer userid = ParseJwtUtil.getUserId();
        return storyIndexService.createIndex(partId,userid);
    }

    //获取游戏进度
    @GetMapping("/frontend/info")
    public R getStoryIndex(@RequestParam("partId")Integer partId){
        return storyIndexService.getStoryIndex(ParseJwtUtil.getUserId(),partId);
    }

    /**
     *  扫码解答
     * @param lineAnswer
     * @param lineId
     * @return
     */
    @RequestMapping("/frontend/update")
    public R checkAnswer(@RequestParam("lineAnswer")String lineAnswer,
                         @RequestParam("lineId")Integer lineId){
        Integer userid = ParseJwtUtil.getUserId();
        return storyIndexService.checkAnswer(userid,lineId,lineAnswer);
    }

    @RequestMapping("/frontend/restart")
    public R restart(){
        Integer userid = ParseJwtUtil.getUserId();
        return storyIndexService.restart(userid);
    }

}
